package com.dcd.controller;

import com.dcd.pojo.Collection_video;
import com.dcd.service.Collection_videoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class Collection_videoController {

    @Autowired
    private Collection_videoService cvs;

    /**
     * 根据登入用户id查询所有视频集合
     * @param user_id 登入用户id
     * @return
     */
    @RequestMapping("/select_collection_videoList_byId")
    public List<Collection_video> select_collection_videoList_byId(@RequestParam Integer user_id){
        return cvs.select_collection_videoList_byId(user_id);
    }

    /**
     * 根据type类型来判断进行添加或者删除
     * @param collection_video 收藏视频表对象
     * @param type 类型
     * @return
     */
    @RequestMapping("/insert_or_delete_collection_video")
    public String insert_or_delete_collection_video(@RequestBody Collection_video collection_video,@RequestParam String type){

        if(type.equals("insert")){
            return "{\"result\":\""+cvs.add_collection_video(collection_video)+"\"}";
        }
        return "{\"result\":\""+cvs.delete_collection_video(collection_video)+"\"}";
    }


    /**
     * 查询登录id 是否收藏了该视频   视频播放页
     * @param collection_video 收藏表对象
     * @return
     */
    @RequestMapping("/select_voider_broadcast")
    public String select_voider_broadcast(@RequestBody Collection_video collection_video){
        return "{\"result\":\""+cvs.select_voider_broadcast(collection_video)+"\"}";
    }
}
